<template>
	<view class="pagesbg">
		<!-- 头部 -->
		<view class="header_bar header_fixed header_main">
			<view class="header">
				<view class="header-goBack" @click="$tools.back(1)"></view>
				<view class="header-title">{{ typeName }}</view>
			</view> 
		</view> 
		<!-- 主体 -->
		<view class="first">
			<view class="firstBox">
				<view class="firstBox-padding">
					<view class="firstBox-form">
						<view class="firstBox-item">
							<view class="firstBox-item-input">
								<image class="firstBox-item-icon" src="@/static/operate/icon-user.png" mode=""></image>
								<input type="text" placeholder="请输入收款人姓名" placeholder-class="inputStyle" v-model="account" />
							</view>
						</view>
						<view class="firstBox-item">
							<view class="firstBox-item-input">
								<image class="firstBox-item-icon" src="@/static/operate/icon-idCard.png" mode=""></image>
								<input type="text" placeholder="请输入银行卡号" placeholder-class="inputStyle" v-model="bankNo" />
							</view>
						</view>
						<view class="firstBox-item">
							<view class="firstBox-item-input">
								<image class="firstBox-item-icon" src="@/static/operate/icon-code.png" mode=""></image>
								<input type="text" placeholder="请输入开户行" placeholder-class="inputStyle" v-model="bank" />
							</view>
						</view>
						<!-- <view class="firstBox-item">
							<view class="firstBox-item-input">
								<image class="firstBox-item-icon" src="@/static/operate/icon-code.png" mode=""></image>
								<input type="number" placeholder="请输入验证码" placeholder-class="inputStyle" v-model="code" />
								<view class="code" @click="sendCode()">{{ remain }}</view>
							</view>
						</view> -->
					</view>
				</view>
			</view>
		</view>
		
		<view class="initBtn" @tap.stop="$u.throttle(confirm,1500)">{{ id ? '修改' : '提交' }}</view>
		
	</view>
</template>

<script>
	export default {
		components:{
		},
		data(){
			return{
				isActive : true,
				isFocus: null,
				toggle: true,
				// 验证码
				remain: '获取验证码',
				isSend: true,
				time: 60,
				timer: null,
				account: '',
				bankNo: '',
				bank: '',
				code: '',
				id: '',
				item: {},
				typeName: '',
			}
		},
		onLoad(options) {
			this.typeName = options.value1;
			if(options.value2 && JSON.stringify(options.value2) != '{}'){
				this.item = JSON.parse(decodeURIComponent(options.value2));
				console.log("item：",this.item);
				this.bank = this.item.bankCardName;
				this.account = this.item.bankName;
				this.bankNo = this.item.withdrawalAccount;
				this.id = this.item.id;
			}
		},
		onShow() {
			this.user = uni.getStorageSync('user');
		},
		// 下拉刷新
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			confirm(){
				if (!this.account) {
					return this.$tools.toast('请输入收款人姓名');
				}
				if (!this.bankNo) {
					return this.$tools.toast('请输入银行卡号');
				}
				var reg = /^([1-9]{1})(\d{15}|\d{18})$/;
				if(!reg.test(this.bankNo)){
					return this.$tools.toast('请输入正确的银行卡号');
				}
				if (!this.bank) {
					return this.$tools.toast('请输入开户行');
				}
				// if (!this.code) {
				// 	return this.$tools.toast('请输入手机验证码');
				// }
				if(this.toggle){
					this.toggle = false;
					var data = {};
					data['type'] = 3;
					data['bankName'] = this.account;
					data['withdrawalAccount'] = this.bankNo;
					data['bankCardName'] = this.bank;
					if(JSON.stringify(this.item) != '{}'){
						data['id'] = this.id;
					}
					console.log("data：",data);
					this.$Ajax('/api/money/bindWithdrawalInfo',
					data,
					res => {
							this.toggle = true;
							this.$tools.toastBack('绑定'+this.typeName+'收款方式成功',1);
						},err =>{
							this.toggle = true;
						}
					)
				}
			},
			sendCode() {
				if(this.isSend == true){ 
					uni.showLoading({
						title: '发送中',
						mask: true
					});
					var data = {
						"phone": this.user.phone,
						"type": '6'
					};
					console.log("data：",data);
					this.$Ajax('/api/common/getCode',
					data,
					res => {
							this.isSend = false;
							this.remain = this.time + 's';
							this.timer = setInterval(() => {
								this.time--;
								this.remain = this.time + 's';
								if (this.time == 0) {
									clearInterval(this.timer);
									this.remain = '重新获取';
									(this.isSend = true), (this.time = 60);
								}
							}, 1000);
						}
					)
					uni.hideLoading();
				}
			},
			/* clear & eye */
			focusInput(index) {
				this.isFocus = index;
			},
			blurInput(index) {
				this.isFocus = null;
			},
			clearData(keyName) {
				for (var key in this.$data) {
					if (key == keyName) {
						this.$data[key] = '';
					}
				}
			},
			toggleEyeStatus(index) {
				this.eyeShowHideArray[index].show = !this.eyeShowHideArray[index].show;
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/common/scss/pages/operate/operate';
</style>